# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter

import os
class XiaohuaPipeline:
    # 重写一个父类方法 进行文件的存储将文件保存到以img_name 为名字的文件中
    fp = None

    # 重写父类的一个方法：该方法组织在开始时候被调用一次
    def open_spider(self, spider):
        print("开始爬虫.....")
        self.fp = open('./xiaohua.csv', "w", encoding="utf-8")
    def process_item(self, item, spider):
        img_name = item["img_name"]
        img_pic = item["img_pic"]
        self.fp.write(img_name+":"+img_pic+"\n")
        return item
    def close_spider(self,spider):
        print("结束爬虫！")
        self.fp.close()

